{% extends 'myadmin/index.html' %}

{% block title %}
<title>BookShop-图书商品编辑</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">图书商品编辑</font>
                        </font>
                    </div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog"></a>
                    </div>
                </div>

                <div class="widget-body am-fr">
                    <form action="{% url 'myadmin_bookedit' bookobj.id %}" method="POST" class="am-form tpl-form-line-form" enctype="multipart/form-data">
                        {% csrf_token %}

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">所属分类：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <select name="classifyid" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                    {% for i in classifydata %}
                                        <option value="{{ i.id }}"
                                            {% if i.pid == 0 %} disabled {% endif %}
                                            {% if i.id == bookobj.classifyid.id %} selected {% endif %}
                                            >{{ i.nbsp }} {{ i.name }}
                                        </option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">书名：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="title" class="tpl-form-input" value="{{ bookobj.title }}" placeholder="请输入书名">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">副标题：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="subhead" class="tpl-form-input" value="{{ bookobj.subhead }}" placeholder="请输入副标题">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">作者：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="author" class="tpl-form-input" value="{{ bookobj.author }}" placeholder="请输入作者">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">出版社：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="publisher" class="tpl-form-input" value="{{ bookobj.publisher }}" placeholder="请输入出版社">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">出版时间：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="date" name="pub_date" value="{{ bookobj.pub_date|date:'Y-m-d' }}" class="tpl-form-input">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">定价：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="number" name="price" class="tpl-form-input" value="{{ bookobj.price }}" placeholder="请输入定价">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">库存数量：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="number" name="num" class="tpl-form-input" value="{{ bookobj.num }}" placeholder="请输入库存数量">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">ISBN：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <input type="number" name="ISBN" class="tpl-form-input" value="{{ bookobj.ISBN }}" placeholder="请输入ISBN">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">内容简介：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <textarea name="context" id="" cols="30" rows="10" placeholder="内容简介、作者简介、目录、前言">{{ bookobj.context }}
                                </textarea>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-3 am-form-label">
                                <font style="vertical-align: inherit;">
                                    <font style="vertical-align: inherit;">封面图：</font>
                                </font>
                            </label>
                            <div class="am-u-sm-9">
                                <div class="am-form-group am-form-file">
                                    <div class="tpl-form-file-img">
                                        <img id="img" src="{{ bookimg }}" alt="">
                                    </div>
                                    <br>
                                    <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                        <i class="am-icon-cloud-upload"></i>
                                        <font style="vertical-align: inherit;">
                                            <font style="vertical-align: inherit;"> 添加封面</font>
                                        </font>
                                    </button>
                                    <input id="imgfile" type="file" name="imgfile" multiple="">
                                </div>
                            </div>
                        </div>
                        <script>
                            // 为上传控件绑定事件（当值发生改变时触发）
                            $('#imgfile').change(function(){
                                // 判断是否选择了图片
                                if(this.files.length == 0){
                                    // 取消了图片选择
                                    $('#img').attr('src','')
                                }else{
                                    // 获取当前用户选择的图片对象
                                    var file = this.files[0]
                                    // 实例化文件读取对象
                                    var read = new FileReader()
                                    // 读取上传的文件数据为DataURL
                                    read.readAsDataURL(file)
                                    // 读取成功后显示图片
                                    read.onload = function(){
                                        $('#img').attr('src',this.result)
                                    }
                                }
                            })
                        </script>

                        <br>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button class="am-btn am-btn-primary tpl-btn-bg-color-success ">
                                    <font style="vertical-align: inherit;">
                                        <font style="vertical-align: inherit;">提交</font>
                                    </font>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}